import { ProFormSelect } from '@ant-design/pro-components';
import {
  DrawerForm,
  ProFormDigit,
  ProFormSwitch,
  ProFormText,
  ProFormTextArea,
} from '@ant-design/pro-form';
import { Col, Row } from 'antd';
import React from 'react';
import * as c from '@/services/consts';

type FormProps = {
  visible: boolean;
  current: API.DeployConfig | undefined;
  onCancel: () => void;
  onSubmit: (values: API.DeployConfig) => Promise<void>;
};

const Form: React.FC<FormProps> = (props) => {
  const { visible, current, onCancel, onSubmit } = props;
  if (!visible) {
    return null;
  }

  return (
    <DrawerForm<API.DeployConfig>
      open={visible}
      initialValues={current}
      title={`${current ? '编辑' : '添加'}配置`}
      autoFocusFirstInput
      width={800}
      onFinish={onSubmit}
      drawerProps={{
        // forceRender: true,
        // destroyOnClose: true,
        // closable: false,
        onClose: onCancel,
        maskClosable: false,
      }}
    >
      <Row gutter={24}>
        <Col span={12}>
          <ProFormText
            name="name"
            label="名称"
            rules={[{ required: true, message: '请输入名称' }]}
            placeholder="请输入名称"
          />
        </Col>
        <Col span={3}>
          <ProFormSwitch
            name="status"
            label="状态"
            initialValue={true}
            fieldProps={{
              defaultChecked: true,
            }}
          />
        </Col>
      </Row>
      <Row gutter={24}>
        <Col span={6}>
          <ProFormDigit 
            name="action" 
            rules={[{ required: true, message: '请输入代码' }]}
            label="代码" 
          />
        </Col>
        <Col span={6}>
          <ProFormSelect
            name='actionType'
            label="代码类型"
            allowClear={false}
            options={c.DeployTypeOptions}
            mode='single'
            fieldProps={{
              listHeight:600
            }}
          />
        </Col>
      </Row>
      <Row gutter={24}>
        <Col span={24}>
          <ProFormText name="x86Url" label="X86程序包地址"/>
        </Col>
      </Row>
      <Row gutter={24}>
        <Col span={24}>
          <ProFormText name="armUrl" label="Arm程序包地址"/>
        </Col>
      </Row>
      <Row gutter={24}>
        <Col span={24}>
          <ProFormTextArea name="remark" label="备注" />
        </Col>
      </Row>
      


      
      
    </DrawerForm>
  );
};

export default Form;
